package com.cn.hjsj.appInterface.appImpl;


import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import org.springframework.stereotype.Component;

import com.cn.hjsj.appInterface.appService.AppPictureUploadService;
import com.cn.hjsj.util.Base64.Base64Util;
import com.cn.hjsj.util.log.LogUtil;

import net.sf.json.JSONObject;
@Component("appPictureUploadImpl")
public class AppPictureUploadImpl implements AppPictureUploadService{
	
	@Override
	public Map<String, Object> pictureUpload(JSONObject object) {
		// TODO Auto-generated method stub
		Map<String, Object> map=new HashMap<String,Object>()
				, maps=new HashMap<String,Object>();
		try{
			Boolean flag = false;
			//图片存放地址
			String url = "E:\\repaircenter\\WebRoot\\WEB-INF\\uploadImg\\";	
			String photo1Name = String.valueOf(UUID.randomUUID())+".jpg";
			flag = Base64Util.GenerateImage(object.getString("photo1"), url+photo1Name);
			if(flag){
				maps.put("photo1", photo1Name);	
			}			
			if(object.containsKey("photo2")&&!"".equals(object.getString("photo2"))){
				flag =false;
				String photo2Name = String.valueOf(UUID.randomUUID())+".jpg";
				flag = Base64Util.GenerateImage(object.getString("photo2"), url+photo2Name);				
				if(flag){
					maps.put("photo2", photo2Name);	
				}
			}
			if(object.containsKey("photo3")&&!"".equals(object.getString("photo3"))){
				flag =false;
				String photo3Name = String.valueOf(UUID.randomUUID())+".jpg";
				flag = Base64Util.GenerateImage(object.getString("photo3"), url+photo3Name);				
				if(flag){
					maps.put("photo3", photo3Name);	
				}
			}
			if(object.containsKey("photo4")&&!"".equals(object.getString("photo4"))){
				flag =false;
				String photo4Name = String.valueOf(UUID.randomUUID())+".jpg";
				flag = Base64Util.GenerateImage(object.getString("photo4"), url+photo4Name);				
				if(flag){
					maps.put("photo4", photo4Name);	
				}
			}
			if(object.containsKey("photo5")&&!"".equals(object.getString("photo5"))){
				flag =false;
				String photo5Name = String.valueOf(UUID.randomUUID())+".jpg";
				flag = Base64Util.GenerateImage(object.getString("photo5"), url+photo5Name);				
				if(flag){
					maps.put("photo5", photo5Name);	
				}
			}
			if(object.containsKey("photo6")&&!"".equals(object.getString("photo6"))){
				flag =false;
				String photo6Name = String.valueOf(UUID.randomUUID())+".jpg";
				flag = Base64Util.GenerateImage(object.getString("photo6"), url+photo6Name);				
				if(flag){
					maps.put("photo6", photo6Name);	
				}
			}
			LogUtil.info("/AppPictureUploadImpl/pictureUpload:调用成功");
			map.put("code", "10000");
			map.put("data", maps);
			map.put("mes", " 图片上传成功！");			
		}catch(Exception e){
			LogUtil.error("/AppPictureUploadImpl/pictureUpload:解析参数异常！"+e.getMessage());
			map.put("code", "30000");
			map.put("mes", "参数列表初始化错误，可能不是合法的JSON数据格式！");
			return map;
		}
		return map;
	}
}
